package com.hoperun.framework.ex;

import java.util.List;

import org.springframework.util.Assert;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * Copyright: Copyright (c) 2014 CNPCMALL <br/>
 * ClassName: CnpcValidationException.java
 * 
 * @Description: 该类的功能描述
 * 
 * @version: v1.0.0
 * @author: fuyu
 * @date: 2014-8-17 上午10:27:59
 * 
 *        Modification History: Date Author Version Description
 *        ---------------------------------------------------------* 2014-8-17
 *        fuyu v1.0.0 修改原因
 */
public class XHZValidationException extends XHZException {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final BindingResult bindingResult;

	public XHZValidationException(BindingResult bindingResult)

	{
		Assert.notNull(bindingResult, "BindingResult must not be null");
		this.bindingResult = bindingResult;
	}

	public XHZValidationException(Object target, String objectName)

	{
		Assert.notNull(target, "Target object must not be null");
		bindingResult = new BeanPropertyBindingResult(target, objectName);
	}

	public final BindingResult getBindingResult()

	{
		return bindingResult;
	}

	public String getErrorMessages() {
		String message = "";
		if (null != bindingResult) {
			List<ObjectError> list = bindingResult.getAllErrors();
			for (ObjectError or : list) {
				message += or.getDefaultMessage() + "  ";
			}
		}

		return message;
	}
}
